define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'goods.rush/index',
        add_url: 'goods.rush/add',
        edit_url: 'goods.rush/edit',
        delete_url: 'goods.rush/delete',
        export_url: 'goods.rush/export',
        modify_url: 'goods.rush/modify',
        sync: 'goods.rush/sync',
        split_url: 'goods.rush/split',
        shangjia_url: 'goods.rush/shangjia',
        getsche: 'goods.rush/getsche',
        tiaojia: 'goods.rush/tiaojia',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh','add','delete','shangjia',
                    [{
                        text: '推送商品',
                        url: init.sync,
                        method: 'request',
                        auth: 'sync',
                        class: 'layui-btn layui-btn-danger layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="true"',
                    },
                    {
                        text: '批量调价',
                        url: init.tiaojia,
                        method: 'open',
                        auth: 'tiaojia',
                        checkbox: true,
                        id: 'id',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    },
                   ],
                ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '商品ID',search: false},
                    {field: 'view_code', title: '商品编号'},
                    {field: 'name', title: '商品名称'},
                    {field: 'view_base_price', title: '初始价(元)',search: false},
                    {field: 'view_price', title: '价格(元)',search: false},
                    {field: 'rusher_name', title: '买方',search: false},
                    {field: 'belong_name', title: '卖方',search: false},
                    {field: 'payimg', title: '支付凭证',templet: ea.table.image,search: false},
                    {field: 'img', title: '商品图片',templet: ea.table.image,search: false},
                    {field: 'sche', title: '抢购场次'},
                    {field: 'bucket', title: '分仓类型',search: false},
                    {field: 'state', title: '商品状态',search: 'select',selectList: {
                        0: '未上架',
                        1: '已上架',
                        2: '待支付',
                        3: '已支付',
                        4: '已确认',
                        5: '待解决',
                        6: '已提货',
                        7: '已发货',
                    },
                    templet: function(d){
                        if(d.state == 0){return "未上架"}
                        if(d.state == 1){return "已上架"}
                        if(d.state == 2){return "待支付"}
                        if(d.state == 3){return "已支付"}
                        if(d.state == 4){return "已确认"}
                        if(d.state == 5){return "待解决"}
                        if(d.state == 6){return "已提货"}
                        if(d.state == 7){return "已发货"}
                    }},
                    {width: 250, title: '操作', 
                    // templet: ea.table.tool
                    templet: function (row) {
                        return ea.table.tool(row, {
                            init, // 初始化的数据变量
                            operat: [
                                [{
                                    text: '拆分商品',
                                    url: init.split_url,
                                    method: 'open',
                                    auth: 'split',
                                    class: 'layui-btn layui-btn-xs layui-btn-success',
                                    extend: 'data-full="true"',
                                },],
                                'edit','delete']
                        })
                     },
                },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        split: function () {
            ea.listen();
        },
        shangjia: function () {
            ea.listen();
        },
        del: function () {
            ea.listen();
        },
        tiaojia: function (){
            ea.listen();
        }
    };
    return Controller;
});